import * as fs from "fs";

export const readFile: (filePath: string) => Promise<string> = (filePath) => {
  return new Promise((resolve, reject) =>
    fs.readFile(filePath, (err, data) => {
      if (err) {
        console.log(err);
        reject(err);
      }

      console.log(data);
      resolve(data.toString());
    })
  );
};

export const writeFile: (filePath: string, data: string) => Promise<string> = (
  filePath,
  data
) => {
  return new Promise((resolve, reject) =>
    fs.writeFile(filePath, data, { encoding: "utf-8" }, (err) => {
      if (err) {
        reject(err);
      }

      resolve("success");
    })
  );
};
